package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.CstService;
import com.example.service.ICstServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  控制器
 * </p>
 *
 * @since 2024-03-05
 * @ClassName CstServiceController
 */
@Controller
@RequestMapping("/cstService")
    public class CstServiceController {

@Autowired
private ICstServiceService cstServiceService;

/**
* 跳转新增页面
*/
@RequestMapping(value = "/add")
public Object toInsert(){
        return"/cstService/add";
    }

/**
* 增
*/
@PostMapping(value = "/save")
@ResponseBody
public Object insert(CstService cstService){
        return cstServiceService.save(cstService);
    }

/**
* 删
*/
@RequestMapping(value = "/del/{id}")
@ResponseBody
public Object delete(@PathVariable(name = "id") Long id){
        return cstServiceService.removeById(id);
    }

/**
* 跳转修改页面
*/
//
@RequestMapping(value = "/edit")
public Object toUpdate(Integer id,Model model){
        model.addAttribute("cstService",cstServiceService.getById(id));
        return"/cstService/edit";
    }

/**
* 改
*/
@PutMapping(value = "/save")
@ResponseBody
public Object update(CstService cstService){
        return cstServiceService.updateById(cstService);
    }


/**
* 分页列表
*/
@RequestMapping(value = "/list")
public Object getUserPage(Page page, CstService cstService,Model model){
        Page pageEntity= cstServiceService.page(page,new QueryWrapper<>(cstService));
        model.addAttribute("cstServicePager",pageEntity);
        return"/cstService/list";
    }

}
